function Trig_CloseBackpack_Actions takes nothing returns nothing
	local unit user = GetTriggerUnit()
	local location userLocation = GetUnitLoc(user)
	local item closeBackpack = GetManipulatedItem()
	local integer closeBackpackId = GetHandleId(closeBackpack)
	local item backpack = LoadItemHandle(udg_BackpackHashtable , closeBackpackId , 10)
	local integer backpackId = GetHandleId(backpack)
	local integer whichSlot = 0
	local item whichItem = null
	local integer backpackSlot = 0
	//--
	call FlushChildHashtable(udg_BackpackHashtable , backpackId)
	loop
	exitwhen whichSlot >= 6
		set whichItem = UnitItemInSlot(user , whichSlot)
		call SetItemPosition(whichItem , GetLocationX(userLocation) , GetLocationY(userLocation))
		call SetItemInvulnerable(whichItem , true)
		call SetItemVisible(whichItem , false)
		call SaveItemHandle(udg_BackpackHashtable , backpackId , whichSlot , whichItem)
	set whichSlot = whichSlot + 1
	endloop
	//取出背包中物品
	set whichSlot = 0
	loop
	exitwhen whichSlot >= 6
		set whichItem = LoadItemHandle(udg_BackpackHashtable , closeBackpackId , whichSlot)
		call SetItemInvulnerable(whichItem , false)
		call SetItemVisible(whichItem , true)
		call UnitAddItem(user , whichItem)
		call UnitDropItemSlot(user , whichItem , whichSlot)
	set whichSlot = whichSlot + 1
	endloop
	call FlushChildHashtable(udg_BackpackHashtable , closeBackpackId)
	call RemoveItem(closeBackpack)
	//--
	set user = null
	call RemoveLocation(userLocation)
	set userLocation = null
	set closeBackpack = null
	set backpack = null
	set whichItem = null
endfunction

function Trig_Backpack_Actions takes nothing returns nothing
	local unit user = GetTriggerUnit()
	local location userLocation = GetUnitLoc(user)
	local item backpack = GetManipulatedItem()
	local integer backpackId = GetHandleId(backpack)
	local item closeBackpack = CreateItem('I008' , GetLocationX(userLocation) , GetLocationY(userLocation))
	local integer closeBackpackId = GetHandleId(closeBackpack)
	local integer whichSlot = 0
	local item whichItem = null
	local integer backpackSlot = 0
	//--
	loop
	exitwhen whichSlot >= 6
		set whichItem = UnitItemInSlot(user , whichSlot)
		if whichItem == backpack then
			set backpackSlot = whichSlot
		endif
		call SetItemPosition(whichItem , GetLocationX(userLocation) , GetLocationY(userLocation))
		call SetItemInvulnerable(whichItem , true)
		call SetItemVisible(whichItem , false)
		call SaveItemHandle(udg_BackpackHashtable , closeBackpackId , whichSlot , whichItem)
	set whichSlot = whichSlot + 1
	endloop
	call UnitAddItem(user , closeBackpack)
	call UnitDropItemSlot(user , closeBackpack , backpackSlot)
	call SaveItemHandle(udg_BackpackHashtable , closeBackpackId , 10 , backpack)
	//取出背包中物品
	set whichSlot = 0
	loop
	exitwhen whichSlot >= 6
		set whichItem = LoadItemHandle(udg_BackpackHashtable , backpackId , whichSlot)
		call UnitAddItem(user , whichItem)
		call UnitDropItemSlot(user , whichItem , whichSlot)
	set whichSlot = whichSlot + 1
	endloop
	//--
	set user = null
	call RemoveLocation(userLocation)
	set userLocation = null
	set backpack = null
	set closeBackpack = null
	set whichItem = null
endfunction

function Trig_CloseBackpack_Conditions takes nothing returns boolean
	return GetItemTypeId(GetManipulatedItem()) == 'I008'
endfunction

function Trig_Backpack_Conditions takes nothing returns boolean
	return GetItemTypeId(GetManipulatedItem()) == 'I007'
endfunction

function InitTrig_Backpack takes nothing returns nothing
	local trigger closeBackpackTrigger = CreateTrigger()
	set gg_trg_Backpack = CreateTrigger()
	set udg_BackpackHashtable = InitHashtable()
	call TriggerRegisterAnyUnitEventBJ( gg_trg_Backpack, EVENT_PLAYER_UNIT_USE_ITEM )
	call TriggerAddCondition( gg_trg_Backpack, Condition( function Trig_Backpack_Conditions ) )
	call TriggerAddAction( gg_trg_Backpack, function Trig_Backpack_Actions )
	
	call TriggerRegisterAnyUnitEventBJ( closeBackpackTrigger, EVENT_PLAYER_UNIT_USE_ITEM )
	call TriggerAddCondition( closeBackpackTrigger, Condition( function Trig_CloseBackpack_Conditions ) )
	call TriggerAddAction( closeBackpackTrigger, function Trig_CloseBackpack_Actions )
endfunction